package com.zhao.dota.processor;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.zhao.dota.common.processor.SteamProcessor;
import com.zhao.dota.struct.SteamResult;
import lombok.Data;
import okhttp3.Request;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ItemProcessor extends SteamProcessor {

    private static final String URL = "https://api.steampowered.com/IEconDOTA2_570/GetGameItems/v1";
//  http://www.dota2.com/jsfeed/itemdata

    public SteamResult<Container> getItemList() {
        Request request = super.buildGet(URL, new Param("language", "zh-cn"));
        String result = super.sendRequest(request);
        SteamResult<Container> itemResult = super.readValue(result, new TypeReference<SteamResult<Container>>() {
        });
        return itemResult;
    }

    @Data
    public static class Container {

        private List<Item> items;

        private Integer status;

    }

    @Data
    public static class Item {

        private Integer id;

        private String name;

        /**
         * 价格
         */
        private Integer cost;

        /**
         * 是否神秘商店
         */
        @JsonProperty("secret_shop")
        private boolean secretShop;

        /**
         * 是否边路商店
         */
        @JsonProperty("side_shop")
        private boolean sideShop;

        /**
         * 是否配方
         */
        private boolean recipe;

        @JsonProperty("localized_name")
        private String localizedName;

    }

}
